package com.li.youhappygo.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.li.youhappygo.mapper.BrandMapper;
import com.li.youhappygo.model.entity.commond.Brand;
import com.li.youhappygo.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    BrandMapper brandMapper;
    @Override
    @Transactional
    public List<Brand> getBrandList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Brand> brandList = brandMapper.selectList(null);
        PageInfo<Brand> brandList2 = new PageInfo<>(brandList);
        List<Brand> currenPage = brandList2.getList();
        return currenPage;
    }

    @Override
    public void save(Brand brand) {
        brandMapper.insert(brand);

    }

    @Override
    public void updateById(Brand brand) {
        brandMapper.updateById(brand);
    }

    @Override
    public void deleteById(Long id) {
        brandMapper.deleteById(id);
    }

    @Override
    public Brand getBrandByID(Long brandId) {
        Brand brand = brandMapper.selectById(brandId);
        return brand;
    }
}
